package hnair.com.shop_ec.sign;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TextInputEditText;
import android.support.v7.widget.AppCompatButton;
import android.view.View;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.OnClick;
import hnair.com.shop.delegates.ShopDelegate;
import hnair.com.shop_ec.R;
import hnair.com.shop_ec.R2;

/**
 * Created by liaowei on 2017/11/17.
 */

public class SignInDelegate extends ShopDelegate {

    @BindView(R2.id.edit_sign_in_name)
    TextInputEditText mName = null;
    @BindView(R2.id.edit_sign_in_password)
    TextInputEditText mPassword = null;

    @OnClick(R2.id.btn_sign_in)
    void onClickSignIn() {
        if (checkForm()) {
            //网络请求提交数据
            Toast.makeText(getContext(), "验证通过", Toast.LENGTH_LONG).show();
        }
    }

    //检测输入的数据是否合法
    private boolean checkForm() {
        final String username = mName.getText().toString();
        final String password = mPassword.getText().toString();

        boolean isPass = true;

        if (username.isEmpty()) {
            mName.setError("请输入用户名");
            isPass = false;
        } else {
            mName.setError(null);
        }

        if (password.isEmpty()) {
            mPassword.setError("请输入密码");
            isPass = false;
        } else {
            mPassword.setError(null);
        }

        return isPass;
    }

    @Override
    public Object setLayout() {
        return R.layout.delegate_sign_in;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {

    }
}
